package cn.fan.redis;

import cn.fan.mapper.FundMainMapper;
import cn.fan.pojo.FundMain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class FundMainRedis {
    private static final String FUNDMAINID = "fundmain:id";
    private static final String FUNDMAINCODE = "fundmain:code";
    private static final String FUNDMAINLIST = "fundmain:list";

    @Autowired
    private FundMainMapper fundMainMapper;

    @Cacheable(value = FUNDMAINID,key = "#id")
    public FundMain getById(long id){
        return fundMainMapper.selectById(id);
    }

    @CachePut(value = FUNDMAINID,key = "#id")
    public FundMain putById(long id){
        return fundMainMapper.selectById(id);
    }

    @CachePut(value = FUNDMAINID,key = "#id")
    public FundMain putById(long id,FundMain fundMain){
        return fundMain;
    }

    @CacheEvict(value = FUNDMAINID,key = "#id")
    public void delete(long id){}

    // code
    @Cacheable(value = FUNDMAINCODE,key = "#code")
    public FundMain getByCode(String code){
        return fundMainMapper.findByCode(code);
    }

    @CachePut(value = FUNDMAINCODE,key = "#code")
    public FundMain putByCode(String code){
        return fundMainMapper.findByCode(code);
    }

    @CachePut(value = FUNDMAINCODE,key = "#code")
    public FundMain putByCode(String code,FundMain fundMain){
        return fundMain;
    }

    @CacheEvict(value = FUNDMAINCODE,key = "#code")
    public void deleteByCode(String code){}

    // list
    @Cacheable(value = FUNDMAINLIST)
    public List<FundMain> getList(){
        List<FundMain> list =fundMainMapper.selectList(null);
        return list;
    }

    @CachePut(value = FUNDMAINLIST)
    public List<FundMain> putList(){
        List<FundMain> list =fundMainMapper.selectList(null);
        return list;
    }

    @CachePut(value = FUNDMAINLIST)
    public List<FundMain> putList(List<FundMain> fundMains){
        return fundMains;
    }

    @CacheEvict(value = FUNDMAINLIST)
    public void deleteList(){}

}
